﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;
using Mocola.Net.Web.Utility;
using System.Collections.Generic;
using Mocola.Security;
using Mocola.Web;
using Mocola.Common;


namespace Mocola.Net.Web
{
    public partial class articlelist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            string sql = "SELECT ArticleID,Title,Created,CASE Category WHEN 0 THEN '制度' ELSE '流程' END AS Category,Author FROM Moc_Articles";
            DataSet dt = Databases.MocolaNet.ExecuteDataSet(CommandType.Text, sql);
            //DataView dv = dt.Tables[0].DefaultView;
            //dv.Sort = "Created";
            //rptArticles.DataSource = dv;
            //rptArticles.DataBind();
            PagedDataSource pg = new PagedDataSource();
            ppArticles.RecordCount = dt.Tables[0].Rows.Count;

            DataView dv = dt.Tables[0].DefaultView;
            dv.Sort = "Created";
            pg.DataSource = dv;
            pg.AllowPaging = true;
            pg.PageSize = ppArticles.PageSize;
            pg.CurrentPageIndex = ppArticles.CurrentPageIndex - 1;
            rptArticles.DataSource = pg;
            rptArticles.DataBind();

            ppArticles.CustomInfoHTML = string.Format("第<font color='red'>{0}</font>/{1}", ppArticles.CurrentPageIndex.ToString(), ppArticles.PageCount.ToString() + "页  每页" + ppArticles.PageSize.ToString() + "条" + " 共" + ppArticles.RecordCount.ToString() + "条记录");
            ppArticles.CustomInfoStyle = "padding-right:10px;";
        }

        protected void ppArticles_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}
